package cn.dlc.com.util;

import cn.dlc.com.controller.JsdwController;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

/**
 * @Author: dlc
 * @Date: 2022/4/29 - 9:47
 */
public class PostUtils {

    public static HttpEntity createRequestPost(String url, String jsonParam) throws Exception{
        CloseableHttpClient client = HttpClients.createDefault();
        // 创建请求
        HttpPost post = new HttpPost(url);
//        HttpGet post = new HttpGet(url);
        // 指定请求头
        post.setHeader("Content-Type", "application/json;charset=UTF-8");
        post.setHeader("slw.jwt.token", JsdwController.token);

        // 请求参数 json格式
        if(StringUtils.isNotBlank(jsonParam)) {
            StringEntity se = new StringEntity(jsonParam);
            post.setEntity(se);
        }
        // 发起请求
        CloseableHttpResponse response = client.execute(post);

        HttpEntity entity = response.getEntity();

        return entity;

    }
}
